package com.im.partchat.ui.activity.conversation;

import android.content.Intent;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;

import com.im.partchat.R;
import com.im.partchat.base.BaseActivity;
import com.im.partchat.utils.Navigation;

import java.util.Locale;

import io.rong.imlib.model.Conversation;

/**
 * Created by hhz on 2017/6/27.
 */

public class ConversationActivity extends BaseActivity {

    /**
     * 对方id
     */
    private String mTargetId;
    /**
     * 会话类型
     */
    private Conversation.ConversationType mConversationType;
    /**
     * title
     */
    private String title;

    private final String TextTypingTitle = "对方正在输入...";
    private final String VoiceTypingTitle = "对方正在讲话...";

    private Handler mHandler;

    public static final int SET_TEXT_TYPING_TITLE = 1;
    public static final int SET_VOICE_TYPING_TITLE = 2;
    public static final int SET_TARGET_ID_TITLE = 0;


    @Override
    public void onLoadDataSuccess(Object o, String flag) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_conversation;
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        if (intent == null || intent.getData() == null)
            return;
        mTargetId = intent.getData().getQueryParameter("targetId");
        mConversationType = Conversation.ConversationType.valueOf(intent.getData()
                .getLastPathSegment().toUpperCase(Locale.US));
        title = intent.getData().getQueryParameter("title");
        if (mConversationType.equals(Conversation.ConversationType.SYSTEM)) {
            setTitle("系统消息");
        } else {
            setTitle(title);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_conversation, menu);

        if (mConversationType.equals(Conversation.ConversationType.GROUP)) {
            menu.findItem(R.id.action_single_setting).setVisible(false);
            menu.findItem(R.id.action_group_setting).setVisible(true);
        } else if (mConversationType.equals(Conversation.ConversationType.PRIVATE) | mConversationType.equals(Conversation.ConversationType.PUBLIC_SERVICE) | mConversationType.equals(Conversation.ConversationType.DISCUSSION)) {
            menu.findItem(R.id.action_single_setting).setVisible(true);
            menu.findItem(R.id.action_group_setting).setVisible(false);
        } else {
            menu.findItem(R.id.action_single_setting).setVisible(false);
            menu.findItem(R.id.action_group_setting).setVisible(false);
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        if (item.getItemId() == R.id.action_single_setting) {

        Navigation.navigateSingleSetting(mTargetId,mConversationType);

        }
        if (item.getItemId() == R.id.action_group_setting) {

        }
        return super.onMenuItemClick(item);
    }
}
